package com.lakeworks.processor;

import com.lakeworks.common.enums.ticket.FlowType;
import com.lakeworks.common.enums.ticket.TicketStatus;
import com.lakeworks.decision.PushTicketDecision;
import com.lakeworks.decision.base.Decision;
import com.lakeworks.domain.TktProcess;
import com.lakeworks.event.AfterSaleEvent;
import com.lakeworks.processor.base.AbstractIssueProcessor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AfterSaleProcessor extends AbstractIssueProcessor<AfterSaleEvent> {

    @Override
    public TktProcess apply(
            AfterSaleEvent event
    ) {
        TktProcess process = super.apply(event);
        event.getTktTicket().setCreateBy(event.getOperator());
        event.getTktTicket().setModifyBy(event.getOperator());
        event.getTktTicket().setFlowId(FlowType.valueOf(event.getTktTicket().getType()).getValue());
        event.getTktTicket().setNodeId(1L);
        event.getTktTicket().setVersion(0);
        event.getTktTicket().setStatus(TicketStatus.AWAITING.name());
       /* if(event.getTktTicket().getType().equals(FlowType.MAJOR_RISK.name())){
            event.getTktTicket().setNodeId(1020l);
            event.getTktTicket().setStatus(TicketStatus.WORKING.name());
        }*/
        process.setComment("工厂:【创建"+FlowType.valueOf(event.getTktTicket().getType()).getName()+"工单】");
        process.setRemark(event.getTktTicket().getRemark());
        List<Decision> list = new ArrayList<>();
        //添加向平台推送工单信息决策
        list.add(new PushTicketDecision(event.getTktTicket()));
        process.setDecisions(list);
        return process;
    }

}
